var e = require("../../../api.js"), t = getApp(), r = require("../../../utils/function.js");

Page({
    data: {
       
        tabList: [ {
            name: "全部",
            type: 0
        }, {
            name: "进行中",
            type: 1
        }, {
            name: "未支付",
            type: 2
        }, {
            name: "已完成",
            type: 3
        }, {
            name: "已取消",
            type: 4
        } ],
        img: r.userImg,
        order: null,
        page: 1
    },
    onLoad: function(e) {
        this.setData({
            tabIndex: e.type || 0
        }), this.getOrderList(e.type || 0), e.uid && t.shareCouponsMessage(e.uid);
    },
    changTab: function(e) {
        var t = e.currentTarget.dataset.idx;
        this.setData({
            tabIndex: t,
            order: []
        }), this.getOrderList(t);
    },
    getOrderList: function(r) {
        var a = this;
        t.request({
            url: e.order.order_list,
            method: "post",
            data: {
                type: r
            },
            success: function(e) {
                1 == e.code && a.setData({
                    order: e.data.data
                });
            }
        });
    },
    goOrderDetail: function(e) {
        e.currentTarget.dataset.id;
        var t = e.currentTarget.dataset.index;
        if (0 != e.currentTarget.dataset.delete) return wx.showToast({
            title: "订单已取消",
            icon: "none"
        }), !1;
        var r = this.data.order;
        if (1 == r[t].is_send && 1 == r[t].initiate && 1 == r[t].is_pay) wx.navigateTo({
            url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id
        }); else if (0 == r[t].is_send && 0 == r[t].apply_delete) wx.navigateTo({
            url: "/pages/map/orderAndDriverGoing/orderAndDriverGoing?order_no=" + e.currentTarget.dataset.id
        }); else if (1 == r[t].apply_delete) wx.navigateTo({
            url: "../orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id
        }); else if (0 == r[t].is_service || 4 == r[t].is_service && 0 == r[t].apply_delete) wx.navigateTo({
            url: 4 == r[t].is_service ? "../../map/getOrderNotGoing/getOrderNotGoing?showdistance=1&order_no=" + e.currentTarget.dataset.id : "../../map/getOrderNotGoing/getOrderNotGoing?order_no=" + e.currentTarget.dataset.id
        }); else if (0 == r[t].apply_delete && 1 == r[t].is_service) wx.navigateTo({
            url: "../../map/orderGoing/orderGoing?order_no=" + e.currentTarget.dataset.id
        }); else if (0 == r[t].apply_delete && 2 == r[t].is_service) {
            if ("已完成" == r[t].status) return wx.navigateTo({
                url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id
            }), !1;
            wx.navigateTo({
                url: "/pages/pay/paidOrder/paidOrder?order_no=" + e.currentTarget.dataset.id
            });
        } else wx.navigateTo({
            url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id
        });
    },
    deleteOrderHandler: function() {
        var e = this;
        wx.showModal({
            title: "删除订单",
            content: "确认是否删除所有订单",
            success: function(t) {
                t.confirm && e.setData({
                    order: []
                });
            },
            fail: function() {}
        });
    },
    onReady: function() {},
    onShow: function() {},
    onReachBottom: function() {
        var r = this, a = this.data, d = a.order, i = a.page;
        a.type;
        wx.showLoading({});
        var s = i + 1;
        this.setData({
            page: s
        }), t.request({
            url: e.order.order_list,
            method: "post",
            data: {
                page: s,
                type: r.data.tabList[r.data.tabIndex].type
            },
            success: function(e) {
                if (wx.hideLoading(), 1 == e.code && 0 != e.data.data.length) {
                    for (var t = 0; t < e.data.data.length; t++) d.push(e.data.data[t]);
                    r.setData({
                        order: d
                    });
                }
            }
        });
    },
    onShareAppMessage: function() {
        return {
            title: t.shareAppMessage().title,
            imageUrl: t.shareAppMessage().imageUrl,
            desc: t.shareAppMessage().desc,
            path: t.shareAppMessage().path
        };
    }
});